package com.future.auth.controller;

import com.alibaba.fastjson.JSONObject;
import com.future.common.api.auth.StatusUser;
import com.future.common.api.feign.RemoteUserService;
import com.future.common.api.result.R;
import com.future.common.security.annoation.Ignore;
import com.future.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: liuby5
 * @CreateTime: 2023-05-06  16:18
 * @Description:
 * @Version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/test-permission")
public class PermissionTestController {
    private RemoteUserService remoteUserService;

    @GetMapping("/info")
    public R getUserInfo(){
        StatusUser user = SecurityUtils.getUser();
        log.info("当前登录用户:{}",JSONObject.toJSONString(user));
        return R.ok(JSONObject.toJSONString(user));
    }


    @Ignore
    @GetMapping("/no-permission")
    public R noPermission(){
        log.info("这个接口无需权限");
        return R.ok(null,"这个接口无需权限");
    }

    @GetMapping("/need-permission")
    @PreAuthorize("@pms.hasPermission('sys_menu_view')")
    public R permission(){
        log.info("这个接口只允许sys_menu_view访问");
        return R.ok();
    }


    @GetMapping("/need-permission-1")
    @PreAuthorize("@pms.hasPermission('aaa')")
    public R permission1(){
        log.info("这个接口只允许aaa访问");
        return R.ok();
    }

    @GetMapping("/test-a")
    @Ignore
    public R testFeign(){
        return remoteUserService.testFeign();
    }
}
